package main

import (
	"fmt"
	"gitlab.w2gou.cn/xbc/go-lib/log"
	"gitlab.w2gou.cn/xbc/go-lib/util"
	"time"
)

func main() {
	defer log.WriteAll()

	//testRbtree1()
	//testRbtree2()

	testFileMapSame()
	//testFileMapRead()

	//testFileMapSpeed()
	//testStdMapSpeed()
	//testRbtreeSpeed()

	//genRand()
}

/*
内存rbtree的速度
1w个顺序key 65ms
1w个随机key 5ms
*/
func testRbtreeSpeed() {
	keys := make([]string, 0)
	for i := 0; i < 100000; i += 1 {
		k := fmt.Sprintf("%010d", i)
		keys = append(keys, k)

		if i == 13 {
			fmt.Println(k)
		}
	}
	keys = util.ReadFileLines("rand2.txt")

	tree := NewTree()

	t1 := time.Now()
	for _, key := range keys {
		tree.Insert(key, key+key)
	}
	t2 := time.Now()
	log.Info4("test", "rbtree", "sub", t2.Sub(t1))

}

/*
内存map的速度
key(10字节) => key+key
1w个顺序key 25ms
1w个随机key 2.3ms
*/
func testStdMapSpeed() {
	keys := make([]string, 0)
	for i := 0; i < 100000; i += 1 {
		k := fmt.Sprintf("%010d", i)
		keys = append(keys, k)

		if i == 13 {
			fmt.Println(k)
		}
	}
	//keys := util.ReadFileLines("rand2.txt")

	mp := make(map[string]string)
	t1 := time.Now()
	for _, k := range keys {
		mp[k] = k + k
	}
	t2 := time.Now()
	log.Info4("test", "normal map", "sub", t2.Sub(t1))
}

func genRand() {
	for i := 0; i < 10000; i += 1 {
		util.AppendFile("rand2.txt", util.RandFakerString(10)+"\n")
	}
}
